package com.turnengine.client.local.location.command;

import com.javabi.command.IExecutableCommand;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.serializer.AbstractCommandDataSerializer;
import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;

/**
 * The Set Coordinate Grid Plugin Data Serializer.
 */
public class SetCoordinateGridPluginDataSerializer extends AbstractCommandDataSerializer<Boolean> implements ISetCoordinateGridPluginDataSerializer {

	/**
	 * Creates a new Set Coordinate Grid Plugin Data Serializer.
	 */
	public SetCoordinateGridPluginDataSerializer() {
		super(SetCoordinateGridPlugin.COMMAND_ID);
	}

	@Override
	public Boolean readReturnValue(IDataReader reader) throws IOException {
		Boolean value = reader.readBooleanObject(true);
		return value;
	}

	@Override
	public void writeReturnValue(IDataWriter writer, Boolean value) throws IOException {
		writer.writeBooleanObject(value, true);
	}

	@Override
	public IExecutableCommand<Boolean> readRequest(IDataReader reader) throws IOException {

		// Read fields
		long loginId = reader.readLong();
		int instanceId = reader.readInt();
		String plugin = reader.readString(true);

		// Create object
		SetCoordinateGridPlugin object = new SetCoordinateGridPlugin();
		object.setLoginId(loginId);
		object.setInstanceId(instanceId);
		object.setPlugin(plugin);
		return object;
	}

	@Override
	public void writeRequest(IDataWriter writer, IExecutableCommand<Boolean> argument) throws IOException {
		SetCoordinateGridPlugin object = (SetCoordinateGridPlugin) argument;

		// Get fields
		long loginId = object.getLoginId();
		int instanceId = object.getInstanceId();
		String plugin = object.getPlugin();

		// Write fields
		writer.writeLong(loginId);
		writer.writeInt(instanceId);
		writer.writeString(plugin, true);
	}

	@Override
	public IExecutableCommandResponse<Boolean> newResponse() {
		return new SetCoordinateGridPluginResponse();
	}
}
